<extend name="Public/common"/>
<block name="style">
</block>
<block name="body">
<div id="main-container" class="container">
	<div class="col-md-2">
		<!--用户中心导航-->
		<include file="User/_nav"/>
	</div>

	<div class="col-md-10">

	<div class="common_box">
		<h3>我的收货地址</h3>
	</div>
	<div class="common_box margin-top-10 clearfix">
    	<button type="button" class="btn btn-lg btn-warning" data-remote="{:U('User/address',array('action'=>'edit'))}" data-toggle="modal">增加收货地址</button>
    </div>
	<notempty name="list">
        <volist name="list" id="list">
            <div class="common_box margin-top-10 address-list-box" data-id="{$list.id}">
            <div class="title">
	            <h4>
	            	{$list.name}
	            	<notempty name="list.first">
	            		<span class="first">默认地址</span>
	            	</notempty>
	            </h4>
            </div>
                <div class="info">
                    <span>收货人：</span>{$list.name}
                </div>
                <div class="info">
                    <span>地区：</span>{$list.province} {$list.city} {$list.district}
                </div>
                <div class="info">
                 	<span>详细地址：</span>{$list.address}
                </div>
                <div class="info">
                 	<span>手机：</span>{$list.phone}
                </div>
                <div class="operate" data-id="{$list.id}">
                <span>
                	<a data-toggle="modal" data-remote="{:U('User/address',array('action'=>'edit','id'=>$list['id']))}">编辑</a>
                </span>
                <empty name="list.first">
		            <span>
	                	<a class="first-address" data-id="{$list.id}" data-url="{:U('User/address',array('action'=>'first','id'=>$list['id']))}">设为默认地址</a>
	                </span>
	            </empty>
                <span>
                	<a data-toggle="modal" data-remote="{:U('User/address',array('action'=>'del','id'=>$list['id']))}">删除</a>
                </span></div>
            </div>
        </volist>
    <else />
    	<div class="common_box margin-top-10 address-list-box">
        	<span class="empty">还没有添加任何收货地址信息...</span>
        </div>
    </notempty>

    <div class="common_box margin-top-10 clearfix">
    	<button type="button" class="btn btn-lg btn btn-warning" data-remote="{:U('User/address',array('action'=>'edit'))}" data-toggle="modal">增加收货地址</button>
    </div>
	</div>
</div>

<script>
$(function(){
	//设置首选地址
	$('.first-address').click(function(){
        var self = $(this);
        var id = {'id':self.attr('data-id')};
        var url = self.attr('data-url');
        $.post(url, id, success, 'json');
        function success(data) {
        if (data.status) {
            toast.success(data.info, '温馨提示');
            setTimeout(function () {
                window.location.href = data.url
            }, 1000);
        } else {
            toast.error(data.info, '温馨提示');
        }
    }
    });
});
</script>
</block>